package cn.stylefeng.guns.modular.order.service.impl;

import java.io.InputStream;
import java.io.Serializable;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import cn.stylefeng.guns.modular.order.model.params.*;
import cn.stylefeng.guns.modular.order.service.*;
import cn.stylefeng.guns.modular.rest.transport.vo.GoodQueryVo;
import cn.stylefeng.guns.modular.storage.model.params.StorageOutParam;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.multipart.MultipartFile;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.hutool.http.HttpRequest;
import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.core.util.DateUtil2;
import cn.stylefeng.guns.modular.basic.entity.BasicAddress;
import cn.stylefeng.guns.modular.basic.entity.BasicCustomer;
import cn.stylefeng.guns.modular.basic.entity.BasicOperate;
import cn.stylefeng.guns.modular.basic.entity.BasicPutgoods;
import cn.stylefeng.guns.modular.basic.entity.BasicWarehouse;
import cn.stylefeng.guns.modular.basic.model.params.BasicAddressParam;
import cn.stylefeng.guns.modular.basic.model.params.BasicCustomerParam;
import cn.stylefeng.guns.modular.basic.model.params.BasicGoodsParam;
import cn.stylefeng.guns.modular.basic.model.params.BasicPutgoodsParam;
import cn.stylefeng.guns.modular.basic.model.params.BasicWarehouseParam;
import cn.stylefeng.guns.modular.basic.model.params.BasicXlbOauth2tokenParam;
import cn.stylefeng.guns.modular.basic.model.result.BasicAddressResult;
import cn.stylefeng.guns.modular.basic.model.result.BasicCustomerResult;
import cn.stylefeng.guns.modular.basic.model.result.BasicGoodsResult;
import cn.stylefeng.guns.modular.basic.model.result.BasicPutgoodsResult;
import cn.stylefeng.guns.modular.basic.model.result.BasicWarehouseResult;
import cn.stylefeng.guns.modular.basic.model.result.BasicXlbOauth2tokenResult;
import cn.stylefeng.guns.modular.basic.service.BasicAddressService;
import cn.stylefeng.guns.modular.basic.service.BasicCustomerService;
import cn.stylefeng.guns.modular.basic.service.BasicGoodsService;
import cn.stylefeng.guns.modular.basic.service.BasicLineService;
import cn.stylefeng.guns.modular.basic.service.BasicOperateService;
import cn.stylefeng.guns.modular.basic.service.BasicPrivatecarService;
import cn.stylefeng.guns.modular.basic.service.BasicPutgoodsService;
import cn.stylefeng.guns.modular.basic.service.BasicWarehouseService;
import cn.stylefeng.guns.modular.basic.service.BasicXlbOauth2tokenService;
import cn.stylefeng.guns.modular.order.entity.OrderTransport;
import cn.stylefeng.guns.modular.order.entity.OrderTransportDetailed;
import cn.stylefeng.guns.modular.order.entity.OrderTransportExcelItem;
import cn.stylefeng.guns.modular.order.entity.StorageTaskXlb;
import cn.stylefeng.guns.modular.order.mapper.OrderTransportMapper;
import cn.stylefeng.guns.modular.order.model.result.OrderPutDetailedResult;
import cn.stylefeng.guns.modular.order.model.result.OrderTransportDetailedResult;
import cn.stylefeng.guns.modular.order.model.result.OrderTransportResult;
import cn.stylefeng.guns.modular.order.model.result.OutOrderDetailedResult;
import cn.stylefeng.guns.modular.storage.service.StorageOutService;
import cn.stylefeng.guns.modular.transport.model.params.TransportDispatchParam;
import cn.stylefeng.guns.modular.transport.model.result.TransportDispatchResult;
import cn.stylefeng.guns.modular.transport.service.TDispatchService;
import cn.stylefeng.guns.modular.transport.service.TransportDispatchService;
import cn.stylefeng.guns.modular.transport.service.TransportReceiptService;
import cn.stylefeng.guns.sys.modular.system.entity.Dept;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.guns.sys.modular.system.service.DeptService;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;

/**
 * 货运订单表 服务实现类
 */
@Service
public class OrderTransportServiceImpl extends ServiceImpl<OrderTransportMapper, OrderTransport> implements OrderTransportService {

    @Resource
    private OrderTransportService orderTransportService;

    @Resource
    private BasicOperateService basicOperateService;

    @Resource
    private BasicCustomerService basicCustomerService;

    @Resource
    private UserService userService;

    @Resource
    private OrderPutDetailedService orderPutDetailedService;

    @Resource
    private OrderTransportDetailedService orderTransportDetailedService;

    @Resource
    private OutOrderDetailedService outOrderDetailedService;

    @Resource
    private TransportDispatchService transportDispatchService;

    @Resource
    private StorageOutService storageOutService;

    @Resource
    private BasicPrivatecarService basicPrivatecarService;

    @Resource
    private TDispatchService tDispatchService;

    @Resource
    private TransportReceiptService transportReceiptService;

    @Resource
    private BasicLineService basicLineService;

    @Resource
    private BasicAddressService basicAddressService;

    @Value("${hxl.api.url}")
    private String hxlApiUrl;

    @Override
    public void add(OrderTransportParam param) {
        OrderTransport entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(OrderTransportParam param) {
        this.removeById(getKey(param));
    }

    @Override
    public void update(OrderTransportParam param) {
        OrderTransport oldEntity = getOldEntity(param);
        OrderTransport newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public OrderTransportResult findBySpec(OrderTransportParam param, Long operateId) {
        return this.baseMapper.findBySpec(param, operateId);
    }

    @Override
    public List<OrderTransportResult> findListBySpec(OrderTransportParam param, String carnumbger, String carState) {
        return this.baseMapper.findListBySpec(param, carnumbger, carState);
    }

    @Override
    public LayuiPageInfo findPageBySpec(OrderTransportParam param, String condition, Long operateId) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param, condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findTmsAnalysislist(OrderTransportParam param, String condition, Long operateId) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findTmsAnalysislist(pageContext, param, condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(OrderTransportParam param) {
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private OrderTransport getOldEntity(OrderTransportParam param) {
        return this.getById(getKey(param));
    }

    private OrderTransport getEntity(OrderTransportParam param) {
        OrderTransport entity = new OrderTransport();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

    @Override
    public OrderTransport findByThelastone() {
        return this.baseMapper.findByThelastone();
    }

    @Override
    public List<OrderTransportResult> findListByids(Long[] ids) {
        return this.baseMapper.findListByids(ids);
    }

    @Resource
    private DeptService deptService;

    /**
     * 获取所属项目单号前缀
     *
     * @param user
     * @return
     */
    public String getOperateIdOrderPrefix(User user) {
        if (user.getOperateId() != null) {
            Dept dept = new Dept();
            dept.setOperateId(user.getOperateId());
            Dept resdept = deptService.findBySpec(dept);
            if (resdept != null) {
                if (ToolUtil.isNotEmpty(resdept.getOrderPrefix())) {
                    return resdept.getOrderPrefix();
                } else {
                    return user.getAccount().substring(0, 3);
                }
            } else {
                return null;
            }
        } else {
            return null;
        }
    }

    @Override
    public void putaddTransport(OrderPutParam orderPutParam, OrderTransportParam orderTransportParam) {
        User user = userService.getcurrentUser();
        BasicCustomer basicCustomer = basicCustomerService.getById(orderPutParam.getPutCustomerId());
        BasicOperate basicOperate = basicOperateService.getById(basicCustomer.getCustomerOperateId());

        orderTransportParam.setOperateId(Long.parseLong(basicOperate.getId().toString()));
        orderTransportParam.setOperateName(basicOperate.getOperateName());
        String trayCode = getOperateIdOrderPrefix(user);
        OrderTransport t = this.orderTransportService.findByThelastone();
        if (t != null) {
            orderTransportParam.setTransportNumber(trayCode + "-" + "HY-" + cn.stylefeng.guns.core.util.DateUtil.getDateBch() + "-" + (t.getId() + 1));
        } else {
            orderTransportParam.setTransportNumber(trayCode + "-" + "HY-" + cn.stylefeng.guns.core.util.DateUtil.getDateBch() + "-1");
        }
        orderTransportParam.setCustomerId(Long.parseLong(basicCustomer.getId().toString()));
        orderTransportParam.setCustomerName(basicCustomer.getCustomerName());
        orderTransportParam.setUndertime(DateUtil2.getDateS());
        orderTransportParam.setCustomerOrder(orderPutParam.getPutCustomerNumber());
        orderTransportParam.setDeliverId(user.getDeliverId());
        orderTransportParam.setDeptId(user.getDeptId());
        orderTransportParam.setCreateName(user.getName());
        orderTransportParam.setTstate("h");
        orderTransportParam.setOrderNumber(orderPutParam.getPutNumber());
        BasicAddress basicAddress = basicAddressService.getById(orderTransportParam.getGetLocationId());
        if (basicAddress != null) {
            orderTransportParam.setKilometer(basicAddress.getKilometer());
            orderTransportParam.setLineId(basicAddress.getLineId());
            orderTransportParam.setLineName(basicAddress.getLineName());
        }
        this.add(orderTransportParam);
    }

    @Override
    public void puteditTransport(OrderPutParam orderPutParam, OrderTransportParam orderTransportParam) {
        OrderTransportParam otp = new OrderTransportParam();
        otp.setCustomerOrder(orderPutParam.getPutCustomerNumber());
        OrderTransportResult otr = orderTransportService.findBySpec(otp, null);
        if (otr == null) {
            putaddTransport(orderPutParam, orderTransportParam);
        } else {
            if ("h".equals(otr.getTstate())) {
                orderTransportParam.setId(otr.getId());

                BasicCustomer basicCustomer = basicCustomerService.getById(orderPutParam.getPutCustomerId());
                BasicOperate basicOperate = basicOperateService.getById(basicCustomer.getCustomerOperateId());

                orderTransportParam.setOperateId(Long.parseLong(basicOperate.getId().toString()));
                orderTransportParam.setOperateName(basicOperate.getOperateName());
                orderTransportParam.setTransportNumber(otr.getTransportNumber());
                orderTransportParam.setCustomerId(Long.parseLong(basicCustomer.getId().toString()));
                orderTransportParam.setCustomerName(basicCustomer.getCustomerName());
                orderTransportParam.setUndertime(DateUtil2.getDateS());
                orderTransportParam.setCustomerOrder(orderPutParam.getPutCustomerNumber());
                orderTransportParam.setDeliverId(userService.getDeliverId());
                orderTransportParam.setDeptId(userService.getDeptId());
                orderTransportParam.setCreateName(userService.getcurrentUser().getName());
                orderTransportParam.setTstate("h");
                orderTransportParam.setOrderNumber(orderPutParam.getPutNumber());
                BasicAddress basicAddress = basicAddressService.getById(orderTransportParam.getGetLocationId());
                if (basicAddress != null) {
                    orderTransportParam.setKilometer(basicAddress.getKilometer());
                    orderTransportParam.setLineId(basicAddress.getLineId());
                    orderTransportParam.setLineName(basicAddress.getLineName());
                }
                this.update(orderTransportParam);
            }
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateTransport(OrderPutParam param) {
        OrderPutDetailedParam dParam = new OrderPutDetailedParam();
        dParam.setPutDetailedNumber(param.getPutNumber());
        List<OrderPutDetailedResult> list = orderPutDetailedService.findListGroupGoodsidBySpec(dParam);

        OrderTransportParam otp = new OrderTransportParam();
        otp.setCustomerOrder(param.getPutCustomerNumber());
        OrderTransportResult otr = this.findBySpec(otp, null);
        if ("h".equals(otr.getTstate())) {
            BigDecimal TotalNum = new BigDecimal(0);//货物单总数
            BigDecimal TotalVolume = new BigDecimal(0);//货物单总体积
            for (OrderPutDetailedResult opr : list) {
                OrderTransportDetailedParam otdp = new OrderTransportDetailedParam();

                BigDecimal w = new BigDecimal(0);
                BigDecimal v = new BigDecimal(0);
                BigDecimal u = new BigDecimal(0);
                if (opr.getDetailedPutweight() != null) {
                    w = new BigDecimal(opr.getDetailedPutweight()).setScale(3, BigDecimal.ROUND_HALF_DOWN);
                    otdp.setGoodsWeight(opr.getGoodsWeight());
                    otdp.setTransportWeight(w.toString());
                }
                if (opr.getDetailedPutvolume() != null) {
                    v = new BigDecimal(opr.getDetailedPutvolume()).setScale(3, BigDecimal.ROUND_HALF_DOWN);
                    otdp.setGoodsVolume(opr.getGoodsVolume());
                    otdp.setTransportPutvolume(v.toString());
                }
                if (opr.getDetailedMoney() != null) {
                    u = new BigDecimal(opr.getDetailedMoney()).setScale(3, BigDecimal.ROUND_HALF_DOWN);
                    otdp.setUnitprice(opr.getDetailedUnitprice());
                    otdp.setTransportMoney(u.toString());
                }

                otdp.setTransportNumber(otr.getTransportNumber());
                otdp.setGoodsName(opr.getDetailedGoodsname());
                otdp.setGoodId(opr.getDetailedGoodsnum());
                otdp.setGoodsNumber(opr.getGoodsNumber());
                otdp.setGoodsNo(opr.getGoodsNo());

                otdp.setRebubbles(opr.getDetailedRebubbles());
                otdp.setLargeclass(opr.getDetailedLargeclass());
                otdp.setGoodstype(opr.getDetailedGoodstype());
                otdp.setConditions(opr.getDetailedPutcondition());

                otdp.setGoodsUnit(opr.getGoodsUnit());
                otdp.setDpacking(opr.getDetailedPacking());
                otdp.setGoodsSpecs(opr.getGoodsSpecs());

                otdp.setBalenum(opr.getDetailedPutbalenum());
                otdp.setNum(opr.getDetailedPutnum());

                otdp.setNotnum(opr.getDetailedPutnum());
                otdp.setNotvolume(opr.getDetailedPutvolume());
                orderTransportDetailedService.add(otdp);

                BigDecimal num = new BigDecimal(otdp.getNum());
                BigDecimal transportPutvolume = new BigDecimal(otdp.getTransportPutvolume());
                BigDecimal nTotalNum = TotalNum.add(num);
                TotalNum = nTotalNum;
                BigDecimal nTotalVolume = TotalVolume.add(transportPutvolume);
                TotalVolume = nTotalVolume;
            }
            otr.setTooNum("0");
            otr.setTooVolume("0");
            otr.setTstate("PENDING_SUBMIT");
            otr.setTotalNum(TotalNum.toString());
            otr.setTotalVolume(TotalVolume.toString());
            ToolUtil.copyProperties(otr, otp);
            this.update(otp);
        }
    }

    @Resource
    private BasicWarehouseService basicWarehouseService;

    /**
     * 出库添加货运单
     *
     * @param outOrderParam
     * @param orderTransportParam
     */
    @Override
    public void outAddTransport(OutOrderParam outOrderParam, OrderTransportParam orderTransportParam) {
        User user = userService.getcurrentUser();
        BasicCustomer basicCustomer = basicCustomerService.getById(outOrderParam.getOutCustomerId());
        BasicWarehouse basicWarehouse = basicWarehouseService.getById(outOrderParam.getOutStorehouseId());

        orderTransportParam.setOperateId(Long.parseLong(basicWarehouse.getWarehouseOperateId().toString()));
        orderTransportParam.setOperateName(basicWarehouse.getWarehouseOperateName());
        OrderTransport transport = this.orderTransportService.findByThelastone();
        String trayCode = getOperateIdOrderPrefix(user);
        if (transport != null) {
            orderTransportParam.setTransportNumber(trayCode + "-" + "HY-" + cn.stylefeng.guns.core.util.DateUtil.getDateBch() + "-" + (transport.getId() + 1));
        } else {
            orderTransportParam.setTransportNumber(trayCode + "-" + "HY-" + cn.stylefeng.guns.core.util.DateUtil.getDateBch() + "-1");
        }
        orderTransportParam.setCustomerId(Long.parseLong(basicCustomer.getId().toString()));
        orderTransportParam.setCustomerName(basicCustomer.getCustomerName());
        orderTransportParam.setUndertime(DateUtil2.getDateS());
        orderTransportParam.setSetMentiontime(outOrderParam.getSetMentiontime());
        orderTransportParam.setCustomerOrder(outOrderParam.getCustomerNumber());
        orderTransportParam.setDeliverId(user.getDeliverId());
        orderTransportParam.setDeptId(user.getDeptId());
        orderTransportParam.setCreateName(user.getName());
        orderTransportParam.setTstate("h");
        orderTransportParam.setNodes(outOrderParam.getNote());
        orderTransportParam.setOrderNumber(outOrderParam.getOutOrderNumber());
        orderTransportParam.setKilometer(outOrderParam.getKilometer());
        orderTransportParam.setOrderSource("WMS");
        BasicAddress basicAddress = basicAddressService.getById(orderTransportParam.getGetLocationId());
        if (basicAddress != null) {
            orderTransportParam.setLineId(basicAddress.getLineId());
            orderTransportParam.setLineName(basicAddress.getLineName());
        }
        this.add(orderTransportParam);
    }

    /**
     * 出库修改货运单
     *
     * @param outOrderParam
     * @param orderTransportParam
     */
    @Override
    public void outEditTransport(OutOrderParam outOrderParam, OrderTransportParam orderTransportParam) {
        OrderTransportParam otp = new OrderTransportParam();
        otp.setCustomerOrder(outOrderParam.getCustomerNumber());
        OrderTransportResult otr = orderTransportService.findBySpec(otp, null);
        if (otr == null) {
            outAddTransport(outOrderParam, orderTransportParam);
        } else {
            if ("h".equals(otr.getTstate())) {
                orderTransportParam.setId(otr.getId());

                BasicCustomer basicCustomer = basicCustomerService.getById(outOrderParam.getOutCustomerId());
                BasicWarehouse basicWarehouse = basicWarehouseService.getById(outOrderParam.getOutStorehouseId());

                orderTransportParam.setOperateId(Long.parseLong(basicWarehouse.getWarehouseOperateId().toString()));
                orderTransportParam.setOperateName(basicWarehouse.getWarehouseOperateName());

                orderTransportParam.setTransportNumber(otr.getTransportNumber());
                orderTransportParam.setCustomerId(Long.parseLong(basicCustomer.getId().toString()));
                orderTransportParam.setCustomerName(basicCustomer.getCustomerName());
                orderTransportParam.setUndertime(DateUtil2.getDateS());
                orderTransportParam.setSetMentiontime(outOrderParam.getSetMentiontime());
                orderTransportParam.setCustomerOrder(outOrderParam.getCustomerNumber());
                orderTransportParam.setDeliverId(userService.getDeliverId());
                orderTransportParam.setDeptId(userService.getDeptId());
                orderTransportParam.setCreateName(userService.getcurrentUser().getName());
                orderTransportParam.setTstate("h");
                orderTransportParam.setNodes(outOrderParam.getNote());
                orderTransportParam.setOrderNumber(outOrderParam.getOutOrderNumber());
                orderTransportParam.setKilometer(outOrderParam.getKilometer());
                BasicAddress basicAddress = basicAddressService.getById(orderTransportParam.getGetLocationId());
                if (basicAddress != null) {
                    orderTransportParam.setLineId(basicAddress.getLineId());
                    orderTransportParam.setLineName(basicAddress.getLineName());
                }
                this.update(orderTransportParam);
            }
        }
    }

    /**
     * 审核  更改货运单
     *
     * @param outOrderParam
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void outUpdateTransport(OutOrderParam outOrderParam) {
        OutOrderDetailedParam outParam = new OutOrderDetailedParam();
        outParam.setDetailedOutNumber(outOrderParam.getOutOrderNumber());
        List<OutOrderDetailedResult> list = outOrderDetailedService.findListGroupGoodsidBySpec(outParam);

        OrderTransportParam orderTransportParam = new OrderTransportParam();
        orderTransportParam.setCustomerOrder(outOrderParam.getCustomerNumber());
        OrderTransportResult orderTransportResult = this.findBySpec(orderTransportParam, null);
        if (orderTransportResult != null) {
            if ("h".equals(orderTransportResult.getTstate())) {
                BigDecimal TotalNum = new BigDecimal("0");//货物单总数
                BigDecimal TotalVolume = new BigDecimal("0");//货物单总体积
                for (OutOrderDetailedResult opr : list) {
                    OrderTransportDetailedParam outTranDetailed = new OrderTransportDetailedParam();

                    BigDecimal v = new BigDecimal("0");
                    BigDecimal w = new BigDecimal("0");
                    BigDecimal u = new BigDecimal("0");
                    if (opr.getDetailedOutWeight() != null) {
                        w = new BigDecimal(opr.getDetailedOutWeight()).setScale(3, BigDecimal.ROUND_HALF_DOWN);
                        outTranDetailed.setGoodsWeight(opr.getDetailedWeight());
                        outTranDetailed.setTransportWeight(w.toString());
                    }
                    if (opr.getDetailedOutVolume() != null) {
                        v = new BigDecimal(opr.getDetailedOutVolume()).setScale(3, BigDecimal.ROUND_HALF_DOWN);
                        outTranDetailed.setGoodsVolume(opr.getDetailedVolume());
                        outTranDetailed.setTransportPutvolume(v.toString());
                        outTranDetailed.setNotvolume(v.toString());
                    }
                    if (opr.getDetailedMoney() != null) {
                        u = new BigDecimal(opr.getDetailedMoney()).setScale(3, BigDecimal.ROUND_HALF_DOWN);
                        outTranDetailed.setUnitprice(opr.getDetailedPrice());
                        outTranDetailed.setTransportMoney(u.toString());
                    }
                    outTranDetailed.setBatchnumber(opr.getDetailedBatchnumber());
                    outTranDetailed.setTransportNumber(orderTransportResult.getTransportNumber());
                    outTranDetailed.setGoodsName(opr.getDetailedGoodsname());
                    outTranDetailed.setGoodId(opr.getDetailedGoodsId());
                    outTranDetailed.setGoodsNumber(opr.getDetailedGoodscode());
                    outTranDetailed.setGoodsNo(opr.getGoodsNo());

                    outTranDetailed.setRebubbles(opr.getDetailedRebubbles());
                    outTranDetailed.setLargeclass(opr.getDetailedLargeclass());
                    outTranDetailed.setGoodstype(opr.getDetailedGoodstype());
                    outTranDetailed.setConditions(opr.getDetailedPutcondition());
                    outTranDetailed.setGoodsUnit(opr.getGoodsUnit());
                    outTranDetailed.setDpacking(opr.getDetailedPacking());
                    outTranDetailed.setGoodsSpecs(opr.getGoodsSpecs());

                    outTranDetailed.setBalenum(opr.getDetailedPutbalenum());
                    outTranDetailed.setNum(opr.getDetailedNumber());

                    outTranDetailed.setNotnum(opr.getDetailedNumber());
                    orderTransportDetailedService.add(outTranDetailed);

                    BigDecimal num = new BigDecimal(outTranDetailed.getNum());
                    BigDecimal transportPutvolume = new BigDecimal(outTranDetailed.getTransportPutvolume());
                    BigDecimal nTotalNum = TotalNum.add(num);
                    TotalNum = nTotalNum;
                    BigDecimal nTotalVolume = TotalVolume.add(transportPutvolume);
                    TotalVolume = nTotalVolume;
                }
                orderTransportResult.setTooNum("0");
                orderTransportResult.setTooVolume("0");
                orderTransportResult.setTstate("PENDING_SUBMIT");
                orderTransportResult.setTotalNum(TotalNum.setScale(3, BigDecimal.ROUND_HALF_DOWN).toString());
                orderTransportResult.setTotalVolume(TotalVolume.setScale(4, BigDecimal.ROUND_HALF_DOWN).toString());
                ToolUtil.copyProperties(orderTransportResult, orderTransportParam);
                this.update(orderTransportParam);
            }
        }

    }

    @Override
    public LayuiPageInfo listgetUnit(OrderTransportParam param) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.listgetUnit(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public OrderTransportResult unitDetailsSingle(OrderTransportParam orderTransportParam) {
        return this.baseMapper.unitDetailsSingle(orderTransportParam);
    }

    @Override
    public List<OrderTransportResult> carDetailsSingle(OrderTransportParam orderTransportParam, String carnumbger, String carState) {
        return this.baseMapper.carDetailsSingle(orderTransportParam, carnumbger, carState);
    }

    @Override
    public LayuiPageInfo dispatchlistPageBySpec(OrderTransportParam param, String condition, Long operateId) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.dispatchlistPageBySpec(pageContext, param, condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public List<OrderTransportResult> carDetailsSingleToo(OrderTransportParam orderTransportParam, Long carId, String dispatch, Long operateId) {
        return this.baseMapper.carDetailsSingleToo(orderTransportParam, carId, dispatch, operateId);
    }

    @Override
    public List<OrderTransportResult> carDetailsSingleToo2(OrderTransportParam orderTransportParam, Long carId, Long operateId) {
        return this.baseMapper.carDetailsSingleToo2(orderTransportParam, carId, operateId);
    }

    @Override
    public List<OrderTransportResult> findListByDeliverId(OrderTransportParam orderTransportParam, String carnumbger, Long carid) {
        return this.baseMapper.findListByDeliverId(orderTransportParam, carnumbger, carid);
    }

    @Override
    public boolean saveBatchList(List<OrderTransportParam> list) {
        return this.baseMapper.saveBatchList(list);
    }

    @Override
    public LayuiPageInfo findByQuery(OrderTransportParam orderTransportParam, String condition, Long operateId) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findByQuery(pageContext, orderTransportParam, condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public List<OrderTransportResult> findByUL(OrderTransportParam orderTransportParam) {
        return this.baseMapper.findByUL(orderTransportParam);
    }

    /**
     * 撤回货运单
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseData revokeS(OrderTransport orderTransport, ResponseData data) {
        //查询  调度明细
        TransportDispatchParam param = new TransportDispatchParam();
        param.setTransportNumber(orderTransport.getTransportNumber());
        List<TransportDispatchResult> list = transportDispatchService.findListBySpec(param);
        if (list.size() > 0) {
            return ResponseData.error("This freight order has been configured！");
        }

        //还原货运明细   未分配数量，体积
        OrderTransportDetailedParam detailedParam = new OrderTransportDetailedParam();
        detailedParam.setTransportNumber(orderTransport.getTransportNumber());
        List<OrderTransportDetailedResult> mxlist = orderTransportDetailedService.findListBySpec(detailedParam);
        for (OrderTransportDetailedResult detailedr : mxlist) {
            OrderTransportDetailedParam updateParam = new OrderTransportDetailedParam();
            updateParam.setId(detailedr.getId());
            updateParam.setNotnum(detailedr.getNum());
            updateParam.setNotvolume(detailedr.getTransportPutvolume());
            orderTransportDetailedService.update(updateParam);
        }

        OrderTransportParam orderTransportParam = new OrderTransportParam();
        orderTransportParam.setId(orderTransport.getId());
        orderTransportParam.setTstate("REVOKED");
        orderTransportParam.setTooVolume("0");
        orderTransportParam.setTooNum("0");
        this.update(orderTransportParam);
        return ResponseData.success();
    }

    @Override
    public LayuiPageInfo listgetUnitNew(OrderTransportParam orderTransportParam) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.listgetUnitNew(pageContext, orderTransportParam);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public List<OrderTransportResult> findListBySpecNew(OrderTransportParam orderTransportParam, Long operateId) {
        return this.baseMapper.findListBySpecNew(orderTransportParam, operateId);
    }

    @Override
    public List<OrderTransportResult> findAutoPrintSum(OrderTransportParam orderTransportParam) {
        return this.baseMapper.findAutoPrintSum(orderTransportParam);
    }


    @Override
    public List<OrderTransportResult> findListBySpecByGetUnitId(OrderTransportParam orderTransportParam, Long operateId) {
        return this.baseMapper.findListBySpecByGetUnitId(orderTransportParam, operateId);
    }

    @Override
    public List<GoodQueryVo> goodQueryList(StorageOutParam param) {
        return this.baseMapper.goodQueryList(param);
    }

    @Override
    public boolean auditorder(Integer id) {
        try {
            OrderTransport orderTransport = orderTransportService.getById(id);
            if (!"PENDING_SUBMIT".equals(orderTransport.getTstate())) {
                return false;
            }
            User user = userService.getcurrentUser();
            OrderTransportParam param = new OrderTransportParam();
            param.setAuditTime(new Date());//审核时间
            param.setAuditUser(user.getUserId());
            param.setAuditName(user.getName());//审核人名称
            param.setTstate("PENDING_TRANSFER");
            param.setId(id);
            orderTransportService.update(param);
        } catch (Exception e) {

        }
        return false;
    }

    @Override
    public List<OrderTransportResult> listgetUnitNewNew(OrderTransportParam orderTransportParam, Long operateId) {
        return this.baseMapper.listgetUnitNewNew(orderTransportParam, operateId);
    }

    @Override
    public List<OrderTransportResult> findListBySpecNewNew(OrderTransportParam orderTransportParam, String carnumbger,
                                                           String carState) {
        return this.baseMapper.findListBySpecNewNew(orderTransportParam, carnumbger, carState);
    }

    @Override
    public List<OrderTransportResult> findListBySpecNewNewNew(OrderTransportParam orderTransportParam,
                                                              String dispatchNumber, Long operateId) {
        return this.baseMapper.findListBySpecNewNewNew(orderTransportParam, dispatchNumber, operateId);
    }

    @Override
    public List<OrderTransportResult> findListBySpecNewsss(OrderTransportParam orderTransportParam,
                                                           String dispatchNumber, Long operateId) {
        return this.baseMapper.findListBySpecNewsss(orderTransportParam, dispatchNumber, operateId);
    }

    private static String getCellValue(Cell cell) {
        if (cell == null) {
            return "";
        }
        if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
            if (DateUtil.isCellDateFormatted(cell)) {
                return HSSFDateUtil.getJavaDate(cell.getNumericCellValue()).toString();
            } else {
                return new BigDecimal(cell.getNumericCellValue()).toString();
            }
        } else if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
            return StringUtils.trimToEmpty(cell.getStringCellValue());
        } else if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
            return StringUtils.trimToEmpty(cell.getCellFormula());
        } else if (cell.getCellType() == Cell.CELL_TYPE_BLANK) {
            return "";
        } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
            return String.valueOf(cell.getBooleanCellValue());
        } else if (cell.getCellType() == Cell.CELL_TYPE_ERROR) {
            return "ERROR";
        } else {
            return cell.toString().trim();
        }

    }

    @Override
    @Transactional(rollbackFor = Exception.class, timeout = 180)
    public ResponseData getExceldata(MultipartFile file, OrderTransportParam orderTransportParam, ResponseData data)
            throws Exception {
        String fileName = file.getOriginalFilename();
        if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) {
            data.setMessage("Incorrect Upload File Format");
            data.setSuccess(false);
        }
        boolean isExcel2003 = true;
        if (fileName.matches("^.+\\.(?i)(xlsx)$")) {
            isExcel2003 = false;
        }
        InputStream is = file.getInputStream();
        Workbook wb = null;
        if (isExcel2003) {
            wb = new HSSFWorkbook(is);
        } else {
            wb = new XSSFWorkbook(is);
        }
        Sheet sheet = wb.getSheetAt(0);

        List<OrderTransportExcelItem> list = new ArrayList<OrderTransportExcelItem>();
        for (int r = 1; r <= sheet.getLastRowNum() + 1; r++) {
            Row row = sheet.getRow(r);
            if (row == null) {
                continue;
            }
            OrderTransportExcelItem excelItem = new OrderTransportExcelItem();

            String fahuoriqi = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(0));
            excelItem.setFahuoriqi(fahuoriqi);//发货日期

            String kehudanhao = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(1));
            excelItem.setKehudanhao(kehudanhao);//客户单号

            String goodscode = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(2));
            excelItem.setGoodscode(goodscode);//商品编号

            String goodsname = getCellValue(row.getCell(3));
            excelItem.setGoodsname(goodsname);//商品名称

            String money = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(4));
            excelItem.setMoney(money);//金额

            String volume = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(5));
            excelItem.setVolume(volume);//体积

            String num = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(6));
            excelItem.setNum(num);//数量

            String weight = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(7));
            excelItem.setWeight(weight);//重量

            String price = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(8));
            excelItem.setPrice(price);//单价

            String shouhuokehu = getCellValue(row.getCell(9));
            excelItem.setShouhuokehu(shouhuokehu);//收货客户

            String shouhuokehudizhi = getCellValue(row.getCell(10));
            excelItem.setShouhuokehudizhi(shouhuokehudizhi);//收货客户地址

            String shouhuolianxiren = getCellValue(row.getCell(11));
            excelItem.setShouhuolianxiren(shouhuolianxiren);//收货联系人

            String shouhuolianxidianhua = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(12));
            excelItem.setShouhuolianxidianhua(shouhuolianxidianhua);//收货联系电话

            String batchnumber = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(13));
            excelItem.setBatchnumber(batchnumber);

            list.add(excelItem);
        }
        if (orderTransportParam.getOperateId() == null || orderTransportParam.getCustomerId() == null || orderTransportParam.getSetUnitId() == null) {
            data.setSuccess(false);
            data.setMessage("Please fill in the basic order information!");
            return data;
        }
        BasicPutgoods fh = basicPutgoodsService.getById(orderTransportParam.getSetUnitId());
        BasicAddressParam basicAddressParam = new BasicAddressParam();
        basicAddressParam.setPutgoodsId(Long.parseLong(fh.getId().toString()));
        BasicAddressResult addressResult = basicAddressService.findBySpec(basicAddressParam);
        if (addressResult == null) {
            return ResponseData.error("The place of loading does not exist! Please maintain it");
        }

        List<OrderTransportParam> transportList = new ArrayList<OrderTransportParam>();//批量保存的 货运订单list
        List<OrderTransportDetailed> transportdList = new ArrayList<OrderTransportDetailed>();//批量保存的 货运订单明细list
        BasicCustomer basicCustomer = basicCustomerService.getById(orderTransportParam.getCustomerId());//客户信息
        BasicOperate basicOperate = basicOperateService.getById(orderTransportParam.getOperateId());//分公司信息
        User user = userService.getcurrentUser();
        Long DeptId = user.getDeptId();
        Long DeliverId = user.getDeliverId();
        String trayCode = getOperateIdOrderPrefix(user);
        String name = user.getName();
        //查询最新 货运订单
        OrderTransport t = orderTransportService.findByThelastone();
        int transportNumber = 1;
        if (t != null) {
            transportNumber = t.getId() + 1;
        }
        DealWithParam dealWithParam = new DealWithParam();
        dealWithParam.setNewCustomersflag(false);
        boolean gflag = true;
        List<String> gmessage = new ArrayList<String>();
        for (OrderTransportExcelItem ExcelItem : list) {
            if (ToolUtil.isEmpty(ExcelItem.getKehudanhao()) && ToolUtil.isEmpty(ExcelItem.getGoodscode()) && ToolUtil.isEmpty(ExcelItem.getShouhuokehu())) {
                break;
            }
            if (ToolUtil.isEmpty(ExcelItem.getKehudanhao())) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚
                data.setSuccess(false);
                data.setMessage("Customer Order Number in imported data cannot be empty!");
                return data;
            }
            if (ToolUtil.isEmpty(ExcelItem.getGoodscode())) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚
                data.setSuccess(false);
                data.setMessage("Commodity Code in imported data cannot be empty!");
                return data;
            }
            if (ToolUtil.isEmpty(ExcelItem.getNum())) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚
                data.setSuccess(false);
                data.setMessage("Quantity in imported data cannot be empty!");
                return data;
            }
            if (ToolUtil.isEmpty(ExcelItem.getShouhuokehu())) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚
                data.setSuccess(false);
                data.setMessage("Consignee Customer in imported data cannot be empty!");
                return data;
            }
            OrderTransportParam otp = new OrderTransportParam();
            otp.setCustomerOrder(ExcelItem.getKehudanhao());//客户单号
            OrderTransportResult otr = orderTransportService.findBySpec(otp, null);
            if (otr == null) {
                //生成货运订单
                boolean whether = false;//判断客户单号  是否重复
                for (OrderTransportParam orp2 : transportList) {
                    if (orp2.getCustomerOrder().equals(otp.getCustomerOrder())) {
                        otp.setTransportNumber(orp2.getTransportNumber());
                        whether = true;
                        break;
                    }
                }
                if (!whether) {
                    otp.setOperateId(orderTransportParam.getOperateId());//分公司id
                    otp.setOperateName(basicOperate.getOperateName());//公司名称
                    otp.setTransportNumber(trayCode + "-" + "HY-" + cn.stylefeng.guns.core.util.DateUtil.getDateBch() + "-" + transportNumber);
                    otp.setCustomerId(orderTransportParam.getCustomerId());//客户id
                    otp.setCustomerName(basicCustomer.getCustomerName());//客户名称
                    otp.setUndertime(DateUtil2.getDateS());//下单时间
                    otp.setTstate("PENDING_SUBMIT");//状态为h
                    if (ToolUtil.isNotEmpty(ExcelItem.getFahuoriqi())) {
                        otp.setSetMentiontime(ExcelItem.getFahuoriqi());
                    } else {
                        otp.setSetMentiontime(cn.stylefeng.guns.core.util.DateUtil.getDate());
                    }
                    otp.setSetUnit(fh.getPutgoodsName());//装货单位
                    otp.setSetUnitId(Long.parseLong(fh.getId().toString()));//装货单位id
                    otp.setSetLocation(addressResult.getAddress());//装货地址
                    otp.setSetLocationId(Long.parseLong(addressResult.getId().toString()));//装货地址id
                    otp.setSetPeople(addressResult.getContacts());//联系人
                    otp.setSetTel(addressResult.getTel());//联系电话

                    toDealWith_fh(otp, basicCustomer, ExcelItem, dealWithParam);//处理单位和地址

                    otp.setDeptId(DeptId);
                    otp.setDeliverId(DeliverId);
                    otp.setCreateName(name);
                    otp.setCreateTime(new Date());
                    otp.setCreateUser(user.getUserId());

                    transportList.add(otp);
                    transportNumber++;
                }

                //判断商品是否存在
                BasicGoodsParam bgp = new BasicGoodsParam();
                bgp.setGoodsNumber(ExcelItem.getGoodscode());
                bgp.setGoodsCustomerId(basicCustomer.getId());
                BasicGoodsResult bgr = basicGoodsService.findBySpec(bgp, null);
                if (bgr == null) {
                    gflag = false;
                    boolean ywg = false;
                    for (String message : gmessage) {
                        if (ExcelItem.getGoodscode().equals(message)) {
                            ywg = true;
                            break;
                        }
                    }
                    if (!ywg) {
                        gmessage.add(ExcelItem.getGoodscode());
                    }
                    continue;
                }
                //新增货运明细
                OrderTransportDetailed outTranDetailed = new OrderTransportDetailed();

                BigDecimal onum = new BigDecimal(ExcelItem.getNum()).setScale(3, BigDecimal.ROUND_HALF_DOWN);
                BigDecimal v = new BigDecimal(0);
                BigDecimal w = new BigDecimal(0);
                BigDecimal u = new BigDecimal(0);
                if (ToolUtil.isNotEmpty(ExcelItem.getVolume())) {
                    BigDecimal volume = new BigDecimal(ExcelItem.getVolume()).setScale(4, BigDecimal.ROUND_HALF_DOWN);
                    v = volume.divide(onum, 7, BigDecimal.ROUND_HALF_DOWN);
                    outTranDetailed.setGoodsVolume(v.toString());
                    outTranDetailed.setTransportPutvolume(volume.toString());
                } else if (ToolUtil.isNotEmpty(bgr.getGoodsVolume())) {
                    v = new BigDecimal(bgr.getGoodsVolume()).setScale(7, BigDecimal.ROUND_HALF_DOWN);
                    outTranDetailed.setGoodsVolume(bgr.getGoodsVolume());
                    outTranDetailed.setTransportPutvolume(v.multiply(onum).setScale(7, BigDecimal.ROUND_HALF_DOWN).toString());
                } else {
                    outTranDetailed.setGoodsVolume("1");
                    outTranDetailed.setTransportPutvolume(onum.toString());
                }
                if (ToolUtil.isNotEmpty(ExcelItem.getWeight())) {
                    BigDecimal weight = new BigDecimal(ExcelItem.getWeight()).setScale(3, BigDecimal.ROUND_HALF_DOWN);
                    w = weight.divide(onum, 3, BigDecimal.ROUND_HALF_DOWN);
                    outTranDetailed.setGoodsWeight(w.toString());
                    outTranDetailed.setTransportWeight(weight.toString());
                } else if (ToolUtil.isNotEmpty(bgr.getGoodsWeight())) {
                    w = new BigDecimal(bgr.getGoodsWeight()).setScale(3, BigDecimal.ROUND_HALF_DOWN);
                    outTranDetailed.setGoodsWeight(bgr.getGoodsWeight());
                    outTranDetailed.setTransportWeight(w.multiply(onum).setScale(3, BigDecimal.ROUND_HALF_DOWN).toString());
                } else {
                    outTranDetailed.setGoodsWeight("1");
                    outTranDetailed.setTransportWeight(onum.toString());
                }

                if (ToolUtil.isNotEmpty(ExcelItem.getPrice())) {
                    u = new BigDecimal(ExcelItem.getPrice()).setScale(3, BigDecimal.ROUND_HALF_DOWN);
                    outTranDetailed.setUnitprice(u.toString());
                } else if (ToolUtil.isNotEmpty(bgr.getGoodsCharging())) {
                    u = new BigDecimal(bgr.getGoodsCharging()).setScale(3, BigDecimal.ROUND_HALF_DOWN);
                    outTranDetailed.setUnitprice(u.toString());
                } else {
                    u = new BigDecimal(10);
                    outTranDetailed.setUnitprice(u.toString());
                }

                if (ToolUtil.isNotEmpty(ExcelItem.getMoney())) {
                    BigDecimal money = new BigDecimal(ExcelItem.getMoney()).setScale(3, BigDecimal.ROUND_HALF_DOWN);
                    outTranDetailed.setTransportMoney(money.toString());
                    outTranDetailed.setUnitprice(money.divide(onum, 3, BigDecimal.ROUND_HALF_DOWN).toString());
                } else {
                    outTranDetailed.setTransportMoney(u.multiply(onum).setScale(3, BigDecimal.ROUND_HALF_DOWN).toString());
                }

                outTranDetailed.setTransportNumber(otp.getTransportNumber());
                outTranDetailed.setGoodsName(bgr.getGoodsName());
                outTranDetailed.setGoodId(Long.parseLong(bgr.getId().toString()));
                outTranDetailed.setGoodsNumber(ExcelItem.getGoodscode());
                outTranDetailed.setGoodsNo(bgr.getGoodsNo());
                outTranDetailed.setRebubbles(bgr.getGoodsHeavybubble());
                outTranDetailed.setDpacking(bgr.getGoodsPacking());
                outTranDetailed.setLargeclass(bgr.getGoodsBigtype());
                outTranDetailed.setGoodstype(bgr.getGoodsType());
                outTranDetailed.setConditions(bgr.getGoodsCondition());
                outTranDetailed.setGoodsUnit(bgr.getGoodsUnit());
                outTranDetailed.setGoodsSpecs(bgr.getGoodsSpecs());

                outTranDetailed.setBalenum(onum.toString());
                outTranDetailed.setNum(onum.toString());
                outTranDetailed.setBatchnumber(ExcelItem.getBatchnumber());

                outTranDetailed.setNotnum(onum.toString());
                outTranDetailed.setNotvolume(outTranDetailed.getTransportPutvolume());
                transportdList.add(outTranDetailed);

                otp = new OrderTransportParam();
                otr = new OrderTransportResult();
            } else {
                dealWithParam.setNewCustomersflag(true);
                dealWithParam.setNewCustomers(dealWithParam.getNewCustomers() + "单号：" + ExcelItem.getKehudanhao() + "已存在；");
            }
        }
        if (!gflag) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚
            String resmessage = "";
            for (String message : gmessage) {
                resmessage += message + "，";
            }
            return ResponseData.error("The commodity in the imported data does not exist! Commodity Code:" + resmessage);
        }
        if (transportList.size() > 0) {
            orderTransportService.saveBatchList(transportList);
            orderTransportDetailedService.saveBatch(transportdList);
        }
        data.setSuccess(true);
        if (dealWithParam.isNewCustomersflag()) {
            data.setCode(450);
            data.setMessage(dealWithParam.getNewCustomers().replaceAll("null", ""));
        }
        return data;
    }

    @Resource
    private BasicGoodsService basicGoodsService;

    @Resource
    private BasicPutgoodsService basicPutgoodsService;

    @Resource
    private XlbTaskApiLogService xlbTaskApiLogService;

    @Override
    public Integer sumDayNewOrderCount(OrderTransportParam orderTransportParam) {
        return this.baseMapper.sumDayNewOrderCount(orderTransportParam);
    }

    @Override
    public Integer sumDayWeiFaYunOrderCount(OrderTransportParam orderTransportParam) {
        return this.baseMapper.sumDayWeiFaYunOrderCount(orderTransportParam);
    }

    @Override
    public Double sumDayOrderVolume(OrderTransportParam orderTransportParam) {
        return this.baseMapper.sumDayOrderVolume(orderTransportParam);
    }

    @Override
    public Integer sumMonthNewOrderCount(OrderTransportParam orderTransportParam) {
        return this.baseMapper.sumMonthNewOrderCount(orderTransportParam);
    }

    @Override
    public Integer sumMonthYqianshouOrderCount(OrderTransportParam orderTransportParam) {
        return this.baseMapper.sumMonthYqianshouOrderCount(orderTransportParam);
    }

    @Override
    public Double sumMonthOrderVolume(OrderTransportParam orderTransportParam) {
        return this.baseMapper.sumMonthOrderVolume(orderTransportParam);
    }

    @Override
    public Integer sumMonthNewOrderCount2(OrderTransportParam orderTransportParam, String month) {
        return this.baseMapper.sumMonthNewOrderCount2(orderTransportParam, month);
    }

    @Override
    public Integer sumMonthYqianshouOrderCount2(OrderTransportParam orderTransportParam2, String month) {
        return this.baseMapper.sumMonthYqianshouOrderCount2(orderTransportParam2, month);
    }

    @Override
    public Integer sumMonthYhuidanOrderCount(OrderTransportParam orderTransportParam3, String month) {
        return this.baseMapper.sumMonthYhuidanOrderCount(orderTransportParam3, month);
    }

    @Override
    public LayuiPageInfo findDispatchPageBySpec(OrderTransportParam orderTransportParam, String condition, Long operateId) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findDispatchPageBySpec(pageContext, orderTransportParam, condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findOrderTransportCountBySpec(OrderTransportParam orderTransportParam, String condition, Long operateId) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findOrderTransportCountBySpec(pageContext, orderTransportParam, condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public void updateBySpec(OrderTransportParam orderTransportParam) {
        this.baseMapper.updateBySpec(orderTransportParam);
    }

    @Override
    public void updateBySpec2(OrderTransportParam orderTransportParam) {
        this.baseMapper.updateBySpec2(orderTransportParam);
    }

    @Override
    public OrderTransportResult findSumBySpec(OrderTransportParam orderTransportParam) {
        return this.baseMapper.findSumBySpec(orderTransportParam);
    }

    @Override
    public List<OrderTransportResult> findGetUnitVol(Long operateId,List<String> xlbClientIdList) {
        return this.baseMapper.findGetUnitVol(operateId,xlbClientIdList);
    }


    @Override
    public void taskJobJh() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar calendar = Calendar.getInstance();

        String now = format.format(calendar.getTime());//当前系统时间

        calendar.add(Calendar.MINUTE, -8);//当前系统时间 的   前8分钟的时间
        String tensecondago = format.format(calendar.getTime());
//      String url = "https://test-api.xlbsoft.com/api/hxl.open.wms.pickOrder.find";
        String url = "https://hxl-api.xlbsoft.com/api/hxl.open.wms.pickOrder.find";
        List<String> pick_finish_time = new ArrayList<String>();
        pick_finish_time.add(tensecondago);
        pick_finish_time.add(now);
//        create_time.add("2023-10-03 15:58:00");
//        create_time.add("2023-10-03 15:58:59");
        //添加日志
        JSONObject json = new JSONObject();
        String post = "报错了，没有请求到";
        BasicCustomerParam param = new BasicCustomerParam();
        List<BasicCustomerResult> clist = basicCustomerService.findpullStoragetaskXlbListBySpec(param);
        for (BasicCustomerResult r : clist) {
            try {
                BasicGoodsParam goodsParam = new BasicGoodsParam();
                goodsParam.setGoodsCustomerId(r.getId());
                goodsParam.setGoodsNumber("sp1");
                BasicGoodsResult sp1 = basicGoodsService.findBySpec(goodsParam, null);//商品
                if (sp1 == null) {
                    continue;
                }
                goodsParam.setGoodsNumber("cl1");
                BasicGoodsResult cl1 = basicGoodsService.findBySpec(goodsParam, null);//拆零商品
                if (cl1 == null) {
                    continue;
                }
                BasicPutgoodsParam basicPutgoodsParam = new BasicPutgoodsParam();
                basicPutgoodsParam.setUnitCategory("SHIP");
                basicPutgoodsParam.setDeptId(r.getDeptId());
                BasicPutgoodsResult sh = basicPutgoodsService.findBySpec(basicPutgoodsParam, Long.parseLong(r.getCustomerOperateId().toString()));//发货
                if (sh == null) {
                    continue;
                }
                BasicAddressParam basicAddressParam = new BasicAddressParam();
                basicAddressParam.setPutgoodsId(Long.parseLong(sh.getId().toString()));
                BasicAddressResult addressResult = basicAddressService.findBySpec(basicAddressParam);
                if (addressResult == null) {
                    continue;
                }

                BasicXlbOauth2tokenParam oauth2tokenParam = new BasicXlbOauth2tokenParam();
                oauth2tokenParam.setDeliverId(r.getDeliverId());
                oauth2tokenParam.setGsnumber(r.getGsnumber());
                BasicXlbOauth2tokenResult oauth2tokenResult = basicXlbOauth2tokenService.findBySpec(oauth2tokenParam);
                if (oauth2tokenResult != null) {
                    if (ToolUtil.isNotEmpty(oauth2tokenResult.getOauth2TokenXlb())) {
                        json = new JSONObject();
                        json.put("store_id", r.getStoreIdXlb());
					if(ToolUtil.isNotEmpty(r.getNeedCheck())&&r.getNeedCheck().equals("1")) {
						json.put("check_finish_time", pick_finish_time);
					} else {
						json.put("pick_finish_time", pick_finish_time);
					}
//                        json.put("pick_finish_time", pick_finish_time);
                        post = HttpRequest.post(url)
                                .header("Authorization", "bearer " + oauth2tokenResult.getOauth2TokenXlb()).body(json.toString()).execute().body();
//					System.out.println("================json："+json+"========================");
//					System.out.println("================post："+post+"========================");
                        JSONObject jsonObject = new JSONObject(post);
                        if (jsonObject.get("code").toString().equals("0")) {
                            List<StorageTaskXlb> xlbs = new ArrayList<StorageTaskXlb>();
                            JSONArray jsonArray = new JSONArray(jsonObject.get("data").toString());
                            for (Object object : jsonArray) {
                                JSONObject jsonObject2 = new JSONObject(object.toString());
                                StorageTaskXlb xlb = new StorageTaskXlb();

                                String fid = jsonObject2.get("fid").toString().replaceAll("\t\r\n", "");
                                if (ToolUtil.isNotEmpty(fid) && !fid.equals("null")) {//单据号
                                    xlb.setFid(fid);
                                } else {
                                    continue;
                                }

                                String store_id = jsonObject2.get("store_id").toString();
                                if (ToolUtil.isNotEmpty(store_id)) {//发货门店id
                                    xlb.setStoreId(store_id);
                                }

                                String store_name = jsonObject2.get("store_name").toString();
                                if (ToolUtil.isNotEmpty(store_name)) {//发货门店名称
                                    xlb.setStoreName(store_name);
                                }

                                String storehouse_id = jsonObject2.get("storehouse_id").toString();
                                if (ToolUtil.isNotEmpty(storehouse_id)) {//发货仓库id
                                    xlb.setStorehouseId(storehouse_id);
                                }

                                String storehouse_name = jsonObject2.get("storehouse_name").toString();
                                if (ToolUtil.isNotEmpty(storehouse_name)) {//发货仓库名称
                                    xlb.setStorehouseName(storehouse_name);
                                }

                                String client_id = jsonObject2.get("client_id").toString();
                                if (ToolUtil.isNotEmpty(client_id)) {//收货客户id
                                    xlb.setClientId(client_id);
                                }

                                String client_name = jsonObject2.get("client_name").toString();
                                if (ToolUtil.isNotEmpty(client_name) && !client_name.equals("null")) {//客户名称
                                    xlb.setClientName(client_name);
                                } else {
                                    continue;
                                }

                                String client_province_name = jsonObject2.get("client_province_name").toString();
                                if (ToolUtil.isNotEmpty(client_province_name) && !client_province_name.equals("null")) {//省
                                    xlb.setClientProvinceName(client_province_name);
                                }

                                String client_city_name = jsonObject2.get("client_city_name").toString();
                                if (ToolUtil.isNotEmpty(client_city_name) && !client_city_name.equals("null")) {//市
                                    xlb.setClientCityName(client_city_name);
                                }

                                String client_district_name = jsonObject2.get("client_district_name").toString();
                                if (ToolUtil.isNotEmpty(client_district_name) && !client_district_name.equals("null")) {//区
                                    xlb.setClientDistrictName(client_district_name);
                                }

                                String client_address = jsonObject2.get("client_address").toString();
                                if (ToolUtil.isNotEmpty(client_address) && !client_address.equals("null")) {//地址
                                    xlb.setClientAddress(client_address);
                                }

                                String item_count = jsonObject2.get("item_count").toString();
                                if (ToolUtil.isNotEmpty(item_count) && !item_count.equals("null")) {//商品数
                                    xlb.setItemCount(item_count);
                                } else {
                                    continue;
                                }

                                String quantity = jsonObject2.get("quantity").toString();
                                if (ToolUtil.isNotEmpty(quantity) && !quantity.equals("null")) {//应拣数量
                                    xlb.setQuantity(quantity);
                                } else {
                                    continue;
                                }

                                String volume = jsonObject2.get("volume").toString();
                                if (ToolUtil.isNotEmpty(volume)) {//体积
                                    xlb.setVolume(volume);
                                }

                                String state = jsonObject2.get("state").toString();
                                if (ToolUtil.isNotEmpty(state)) {//
                                    xlb.setState(state);
                                }

                                String order_type = jsonObject2.get("order_type").toString();
                                if (ToolUtil.isNotEmpty(order_type)) {//
                                    xlb.setOrderType(order_type);
                                }

                                String create_by = jsonObject2.get("create_by").toString();
                                if (ToolUtil.isNotEmpty(create_by)) {//制单人
                                    xlb.setCreateBy(create_by);
                                }

                                String create_time = jsonObject2.get("create_time").toString();
                                if (ToolUtil.isNotEmpty(create_time)) {//制单时间
                                    xlb.setCreateTime(create_time);
                                }

                                String out_application_order_fid = jsonObject2.get("out_application_order_fid").toString();
                                if (ToolUtil.isNotEmpty(out_application_order_fid)) {//关联出库申请单
                                    xlb.setOutApplicationOrderFid(out_application_order_fid);
                                }

                                String demolition = jsonObject2.get("demolition").toString();
                                if (ToolUtil.isNotEmpty(demolition)) {//是否拆零
                                    xlb.setDemolition(demolition);
                                }

                                String delivery_date = jsonObject2.get("delivery_date").toString();
                                if (ToolUtil.isNotEmpty(delivery_date)) {//配送日期
                                    xlb.setDeliveryDate(delivery_date);
                                }

                                String pallets = jsonObject2.get("pallets").toString().replaceAll("\t\r\n", "");
                                if (ToolUtil.isNotEmpty(pallets) && !pallets.equals("null")) {//托盘号
                                    OrderTransportParam ch = new OrderTransportParam();
                                    ch.setCustomerOrder(pallets + "_" + fid);
                                    OrderTransportResult chr = this.checkyouwu(ch);
                                    if (chr != null) {
                                        continue;
                                    }
                                    boolean cunzaima = false;
                                    for (StorageTaskXlb fxlb : xlbs) {
                                        String kehudanhao = fxlb.getPallets() + "_" + fxlb.getFid();
                                        if (kehudanhao.equals(pallets + "_" + fid)) {
                                            cunzaima = true;
                                            break;
                                        }
                                    }
                                    if (cunzaima) {
                                        continue;
                                    }
                                    xlb.setPallets(pallets);
                                } else {
                                    continue;
                                }

                                String check_finish_time2 = jsonObject2.get("check_finish_time").toString();
                                if (ToolUtil.isNotEmpty(check_finish_time2)) {//质检完成时间
                                    xlb.setCheckFinishTime(check_finish_time2);
                                }

                                String channel_name = jsonObject2.get("channel_name").toString();
                                if (ToolUtil.isNotEmpty(channel_name)) {//通道号
                                    xlb.setChannelName(channel_name);
                                }

                                if (ToolUtil.isNotEmpty(demolition) && demolition.equals("true")) {
                                    String box_count = jsonObject2.get("box_count").toString();
                                    if (ToolUtil.isNotEmpty(box_count) && !box_count.equals("null")) {//封箱拆零数
                                        xlb.setBoxCount(box_count);
                                    }
                                }

                                xlbs.add(xlb);
                            }
                            if (xlbs.size() > 0) {
                                List<OrderTransportParam> transportList = new ArrayList<OrderTransportParam>();//批量保存的 货运订单list
                                List<OrderTransportDetailedParam> transportdList = new ArrayList<OrderTransportDetailedParam>();//批量保存的 货运订单list
                                BasicOperate basicOperate = basicOperateService.getById(r.getCustomerOperateId());//分公司信息
                                Long DeptId = r.getDeptId();
                                Long DeliverId = r.getDeliverId();
                                String trayCode = "HX";
                                String name = "系统";
                    			int zz = 1;

                                BigDecimal as = new BigDecimal("0");
                                for (StorageTaskXlb xlb : xlbs) {
                                    OrderTransportParam addp = new OrderTransportParam();
                                    addp.setOperateId(Long.parseLong(r.getCustomerOperateId().toString()));//分公司id
                                    addp.setOperateName(basicOperate.getOperateName());//公司名称
                                    addp.setCustomerOrder(xlb.getPallets() + "_" + xlb.getFid());
                                    addp.setTransportNumber(trayCode + "HY" + cn.stylefeng.guns.core.util.DateUtil.getDatesBch() + cn.stylefeng.guns.core.util.DateUtil.getRandomNumber()+zz);
                    				zz++;
                                    addp.setOrderNumber(xlb.getFid());
                                    addp.setXlbClientId(xlb.getClientId());
                                    if (xlb.getDemolition().equals("true")) {
                                        addp.setDemolition("拆零");
                                        addp.setPieceNumber(xlb.getBoxCount());
                                    }
                                    addp.setOrderSource("新零帮");
                                    addp.setCustomerId(Long.parseLong(r.getId().toString()));//客户id
                                    addp.setCustomerName(r.getCustomerName());//客户名称
                                    addp.setUndertime(DateUtil2.getDateS());//下单时间
                                    addp.setSetMentiontime(cn.stylefeng.guns.core.util.DateUtil.getDate());//发货日期
                                    addp.setStockPort(xlb.getChannelName());

                                    addp.setSetUnit(sh.getPutgoodsName());//装货单位
                                    addp.setSetUnitId(Long.parseLong(sh.getId().toString()));//装货单位id
                                    addp.setSetLocation(addressResult.getAddress());//装货地址
                                    addp.setSetLocationId(Long.parseLong(addressResult.getId().toString()));//装货地址id
                                    addp.setSetPeople(addressResult.getContacts());//联系人
                                    addp.setSetTel(addressResult.getTel());//联系电话

                                    toDealWith4(addp, r, xlb);//处理单位和地址

                                    addp.setDeptId(DeptId);
                                    addp.setDeliverId(DeliverId);
                                    addp.setCreateName(name);
                                    addp.setCreateTime(new Date());

                                    addp.setSubmitName(name);
                                    addp.setTooNum("0");
                                    addp.setTooVolume("0");
                                    addp.setTotalNum(xlb.getQuantity());
                                    addp.setGoodsNum(xlb.getItemCount());
                                    addp.setTotalVolume(xlb.getVolume());
                                    addp.setTstate("PENDING_TRANSFER");

                                    //新增货运明细
                                    OrderTransportDetailedParam outTranDetailed = new OrderTransportDetailedParam();

                                    BigDecimal onum = new BigDecimal(xlb.getQuantity()).setScale(3, BigDecimal.ROUND_HALF_DOWN);
                                    if (onum.compareTo(as) != 1) {
                                        continue;
                                    }
                                    if (ToolUtil.isNotEmpty(xlb.getVolume())) {
                                        BigDecimal v = new BigDecimal(xlb.getVolume()).setScale(7, BigDecimal.ROUND_HALF_DOWN);
                                        outTranDetailed.setGoodsVolume(v.divide(onum, 7, BigDecimal.ROUND_HALF_DOWN).toString());
                                        outTranDetailed.setTransportPutvolume(xlb.getVolume());
                                    } else {
                                        outTranDetailed.setGoodsVolume("1");
                                        outTranDetailed.setTransportPutvolume(onum.toString());
                                    }
                                    outTranDetailed.setGoodsWeight("1");
                                    outTranDetailed.setTransportWeight(onum.toString());

                                    outTranDetailed.setUnitprice("1");
                                    outTranDetailed.setTransportMoney(onum.toString());

                                    outTranDetailed.setTransportNumber(addp.getTransportNumber());

                                    if (xlb.getDemolition().equals("true")) {
                                        outTranDetailed.setGoodsName(cl1.getGoodsName());
                                        outTranDetailed.setGoodId(Long.parseLong(cl1.getId().toString()));
                                        outTranDetailed.setGoodsNumber(cl1.getGoodsNumber());
                                        outTranDetailed.setGoodsNo(cl1.getGoodsNo());
                                        outTranDetailed.setRebubbles(cl1.getGoodsHeavybubble());
                                        outTranDetailed.setDpacking(cl1.getGoodsPacking());
                                        outTranDetailed.setLargeclass(cl1.getGoodsBigtype());
                                        outTranDetailed.setGoodstype(cl1.getGoodsType());
                                        outTranDetailed.setConditions(cl1.getGoodsCondition());
                                        outTranDetailed.setGoodsUnit(cl1.getGoodsUnit());
                                        outTranDetailed.setGoodsSpecs(cl1.getGoodsSpecs());
                                    } else {
                                        outTranDetailed.setGoodsName(sp1.getGoodsName());
                                        outTranDetailed.setGoodId(Long.parseLong(sp1.getId().toString()));
                                        outTranDetailed.setGoodsNumber(sp1.getGoodsNumber());
                                        outTranDetailed.setGoodsNo(sp1.getGoodsNo());
                                        outTranDetailed.setRebubbles(sp1.getGoodsHeavybubble());
                                        outTranDetailed.setDpacking(sp1.getGoodsPacking());
                                        outTranDetailed.setLargeclass(sp1.getGoodsBigtype());
                                        outTranDetailed.setGoodstype(sp1.getGoodsType());
                                        outTranDetailed.setConditions(sp1.getGoodsCondition());
                                        outTranDetailed.setGoodsUnit(sp1.getGoodsUnit());
                                        outTranDetailed.setGoodsSpecs(sp1.getGoodsSpecs());
                                    }

                                    outTranDetailed.setBalenum(onum.toString());
                                    outTranDetailed.setNum(onum.toString());

                                    outTranDetailed.setNotnum(onum.toString());
                                    outTranDetailed.setNotvolume(outTranDetailed.getTransportPutvolume());
                                    transportdList.add(outTranDetailed);

                                    transportList.add(addp);
                                }
                                if (transportList.size() > 0) {
                                    this.saveBatchList(transportList);
                                    this.orderTransportDetailedService.saveBatchList(transportdList);
                                }
                            }
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
				post = e.getMessage();
            } finally {
                this.xlbTaskApiLogService.add(XlbTaskApiLogParam.builder()
                        .apiUrl(url)
                        .apiReq(json.toString())
                        .crtTime(new Date())
                        .apiRep(post)
                        .build());
            }
        }
    }

    private void toDealWith4(OrderTransportParam addp, BasicCustomerResult r, StorageTaskXlb xlb) {
        //查询卸货单位 是否存在
        BasicPutgoods bpgp3 = new BasicPutgoods();
        bpgp3.setPutgoodsCustomerId(r.getId());//客户id
        bpgp3.setPutgoodsName(xlb.getClientName());//单位名称 
        BasicPutgoods bputr2 = basicPutgoodsService.lambdaQuery()
                .eq(BasicPutgoods::getPutgoodsCustomerId, r.getId())
                .eq(BasicPutgoods::getPutgoodsName, xlb.getClientName())
                .last("LIMIT 1")
                .one();
        if (bputr2 == null) {
            bpgp3.setPutgoodsOperateName(r.getCustomerName());//客户名称
            bpgp3.setDeliverId(r.getDeliverId());
            bpgp3.setDeptId(r.getDeptId());
            basicPutgoodsService.save(bpgp3);
            addp.setGetUnit(xlb.getClientName());//卸货单位
            addp.setGetUnitId(Long.parseLong(bpgp3.getId().toString()));//卸货单位id

            BasicAddress bap3 = new BasicAddress();
            bap3.setPutgoodsName(xlb.getClientName());
            bap3.setPutgoodsId(Long.parseLong(bpgp3.getId().toString()));
            bap3.setSheng(xlb.getClientProvinceName());
            bap3.setShi(xlb.getClientCityName());
            bap3.setQu(xlb.getClientDistrictName());
            if (ToolUtil.isNotEmpty(xlb.getClientAddress())) {
                bap3.setAddress(xlb.getClientAddress());
            } else {
                bap3.setAddress(xlb.getClientName());
            }
            bap3.setLongitude("0");
            bap3.setLatitude("0");
            bap3.setSwitchWl("1");
            bap3.setSwitchBj("1500");//提货围栏半径 默认100米
            bap3.setSwitchBj2("2000");//收货围栏半径 默认100米
            basicAddressService.save(bap3);
            addp.setGetLocationId(Long.parseLong(bap3.getId().toString()));//卸货地址id
            addp.setGetLocation(bap3.getAddress());//卸货地址
        } else {
            addp.setGetUnit(xlb.getClientName());//卸货单位
            addp.setGetUnitId(Long.parseLong(bputr2.getId().toString()));//卸货单位id
            //查询卸货地点 是否存在
            BasicAddress bap3 = new BasicAddress();
            bap3.setPutgoodsId(Long.parseLong(bputr2.getId().toString()));//单位id
            BasicAddress bar2 = basicAddressService.lambdaQuery()
                    .eq(BasicAddress::getPutgoodsId, bputr2.getId())
                    .last("LIMIT 1")
                    .one();

            if (bar2 != null) {
                addp.setGetLocationId(Long.parseLong(bar2.getId().toString()));//卸货地址id
                addp.setGetLocation(bar2.getAddress());//卸货地址
                addp.setGetPeople(bar2.getContacts());//联系人
                addp.setGetTel(bar2.getTel());//联系电话
                addp.setKilometer(bar2.getKilometer());
                addp.setLineId(bar2.getLineId());
                addp.setLineName(bar2.getLineName());
            } else {//如果没有地址 ，  卸货地址为 单位名称
                bap3.setSheng(xlb.getClientProvinceName());
                bap3.setShi(xlb.getClientCityName());
                bap3.setQu(xlb.getClientDistrictName());
                if (ToolUtil.isNotEmpty(xlb.getClientAddress())) {
                    bap3.setAddress(xlb.getClientAddress());
                } else {
                    bap3.setAddress(bputr2.getPutgoodsName());
                }
                bap3.setPutgoodsName(bputr2.getPutgoodsName());//单位名称
                bap3.setLongitude("0");
                bap3.setLatitude("0");
                bap3.setSwitchWl("1");
                bap3.setSwitchBj("1500");//提货围栏半径 默认100米
                bap3.setSwitchBj2("2000");//收货围栏半径 默认100米
                basicAddressService.save(bap3);
                addp.setGetLocation(bap3.getAddress());//卸货地址
                addp.setGetLocationId(Long.parseLong(bap3.getId().toString()));//卸货地址id
            }
        }
    }

    private void toDealWith41(OrderTransportParam addp, BasicCustomerResult r, StorageTaskXlb xlb) {
        //查询卸货单位 是否存在
        BasicPutgoodsParam bpgp3 = new BasicPutgoodsParam();
        bpgp3.setPutgoodsCustomerId(r.getId());//客户id
        bpgp3.setPutgoodsName(xlb.getClientName());//单位名称 
        BasicPutgoodsResult bputr2 = basicPutgoodsService.findBySpec(bpgp3, null);
        if (bputr2 == null) {
            bpgp3.setPutgoodsOperateName(r.getCustomerName());//客户名称
            bpgp3.setDeliverId(r.getDeliverId());
            bpgp3.setDeptId(r.getDeptId());
            basicPutgoodsService.add(bpgp3);
            BasicPutgoodsParam bpgp4 = new BasicPutgoodsParam();
            bpgp4.setPutgoodsCustomerId(r.getId());//客户id
            bpgp4.setPutgoodsName(xlb.getClientName());//单位名称
            bputr2 = basicPutgoodsService.findBySpec(bpgp4, null);
        }
        addp.setGetUnit(bputr2.getPutgoodsName());//卸货单位
        addp.setGetUnitId(Long.parseLong(bputr2.getId().toString()));//卸货单位id
        //查询卸货地点 是否存在
        BasicAddressParam bap3 = new BasicAddressParam();
        bap3.setPutgoodsId(Long.parseLong(bputr2.getId().toString()));//单位id
        BasicAddressResult bar2 = basicAddressService.findBySpec(bap3);//通过单位id 地址 查询
        if (bar2 != null) {
            addp.setGetLocationId(Long.parseLong(bar2.getId().toString()));//卸货地址id
            addp.setGetLocation(bar2.getAddress());//卸货地址
            addp.setGetPeople(bar2.getContacts());//联系人
            addp.setGetTel(bar2.getTel());//联系电话
            addp.setKilometer(bar2.getKilometer());
            addp.setLineId(bar2.getLineId());
            addp.setLineName(bar2.getLineName());
        } else {//如果没有地址 ，  卸货地址为 单位名称
            bap3.setSheng(xlb.getClientProvinceName());
            bap3.setShi(xlb.getClientCityName());
            bap3.setQu(xlb.getClientDistrictName());
            if (ToolUtil.isNotEmpty(xlb.getClientAddress())) {
                bap3.setAddress(xlb.getClientAddress());
            } else {
                bap3.setAddress(bputr2.getPutgoodsName());
            }
            bap3.setPutgoodsName(bputr2.getPutgoodsName());//单位名称
            bap3.setLongitude("0");
            bap3.setLatitude("0");
            bap3.setSwitchWl("1");
            bap3.setSwitchBj("1500");//提货围栏半径 默认100米
            bap3.setSwitchBj2("2000");//收货围栏半径 默认100米
            basicAddressService.add(bap3);
            BasicAddressParam bap4 = new BasicAddressParam();
            bap4.setPutgoodsId(Long.parseLong(bputr2.getId().toString()));
            bap4.setAddress(xlb.getClientName());
            bar2 = basicAddressService.findBySpec(bap4);
            addp.setGetLocation(bar2.getAddress());//卸货地址
            addp.setGetLocationId(Long.parseLong(bar2.getId().toString()));//卸货地址id
            addp.setGetPeople(bar2.getContacts());//联系人
            addp.setGetTel(bar2.getTel());//联系电话
        }
    }

    //处理单位地址
    private void toDealWith_fh(OrderTransportParam oodp, BasicCustomer basicCustomer, OrderTransportExcelItem ExcelItem, DealWithParam dealWithParam) {
        User user = userService.getcurrentUser();
        //查询卸货单位 是否存在
        BasicPutgoodsParam bpgp3 = new BasicPutgoodsParam();
        bpgp3.setPutgoodsCustomerId(basicCustomer.getId());//客户id
        bpgp3.setPutgoodsName(ExcelItem.getShouhuokehu());//单位名称  (Excel导入数据中 的收货客户)
        if (ToolUtil.isNotEmpty(ExcelItem.getShouhuokehudizhi())) {
            bpgp3.setLocationAddress(ExcelItem.getShouhuokehudizhi());
        }
        BasicPutgoodsResult bputr2 = basicPutgoodsService.findBySpec(bpgp3, null);
        if (bputr2 == null) {
            bpgp3.setPutgoodsOperateName(basicCustomer.getCustomerName());//客户名称
            bpgp3.setDeliverId(user.getDeliverId());
            bpgp3.setDeptId(user.getDeptId());
            basicPutgoodsService.add(bpgp3);
            dealWithParam.setNewCustomersflag(true);
            dealWithParam.setNewCustomers(dealWithParam.getNewCustomers() + "New Consignee Unit：" + ExcelItem.getShouhuokehu() + "，Please promptly maintain the route and correct the address for the new unit to avoid affecting vehicle dispatching and driver delivery.");
            BasicPutgoodsParam bpgp4 = new BasicPutgoodsParam();
            bpgp4.setPutgoodsCustomerId(basicCustomer.getId());//客户id
            bpgp4.setPutgoodsName(ExcelItem.getShouhuokehu());//单位名称
            bputr2 = basicPutgoodsService.findBySpec(bpgp4, null);
        }
        oodp.setGetUnit(bputr2.getPutgoodsName());//卸货单位
        oodp.setGetUnitId(Long.parseLong(bputr2.getId().toString()));//卸货单位id
        //查询卸货地点 是否存在
        BasicAddressParam bap3 = new BasicAddressParam();
        bap3.setPutgoodsId(Long.parseLong(bputr2.getId().toString()));//单位id
        if (ToolUtil.isNotEmpty(ExcelItem.getShouhuokehudizhi())) {
            bap3.setAddress(ExcelItem.getShouhuokehudizhi());
        }
        BasicAddressResult bar2 = basicAddressService.findBySpec(bap3);//通过单位id 地址 查询
        if (bar2 != null) {
            oodp.setGetLocationId(Long.parseLong(bar2.getId().toString()));//卸货地址id
            if (ToolUtil.isNotEmpty(ExcelItem.getShouhuokehudizhi())) {
                bap3.setAddress(ExcelItem.getShouhuokehudizhi());
                oodp.setGetLocation(ExcelItem.getShouhuokehudizhi());//卸货地址
            } else {
                oodp.setGetLocation(bar2.getAddress());//卸货地址
            }
            if (ToolUtil.isNotEmpty(ExcelItem.getShouhuolianxiren())) {
                bap3.setContacts(ExcelItem.getShouhuolianxiren());
                oodp.setGetPeople(ExcelItem.getShouhuolianxiren());//联系人
            } else {
                oodp.setGetPeople(bar2.getContacts());//联系人
            }
            if (ToolUtil.isNotEmpty(ExcelItem.getShouhuolianxidianhua())) {
                bap3.setTel(ExcelItem.getShouhuolianxidianhua());
                oodp.setGetTel(ExcelItem.getShouhuolianxidianhua());//联系电话
            } else {
                oodp.setGetTel(bar2.getTel());//联系电话
            }
            bap3.setId(bar2.getId());
            basicAddressService.update(bap3);
            oodp.setKilometer(bar2.getKilometer());
            oodp.setLineId(bar2.getLineId());
            oodp.setLineName(bar2.getLineName());
        } else if (bar2 == null && ToolUtil.isEmpty(ExcelItem.getShouhuokehudizhi())) {//如果没有地址 并且Excel中收货客户地址 为空，  卸货地址为 单位名称
            bap3.setAddress(bputr2.getPutgoodsName());//地点 为单位名称
            bap3.setPutgoodsName(bputr2.getPutgoodsName());//单位名称
            bap3.setTel(bputr2.getPutgoodsTel());//联系电话 (单位 的联系电话)
            bap3.setContacts(bputr2.getPutgoodsContacts());
            bap3.setLongitude("0");
            bap3.setLatitude("0");
            bap3.setSwitchWl("1");
            bap3.setSwitchBj("1500");//提货围栏半径 默认100米
            bap3.setSwitchBj2("2000");//收货围栏半径 默认100米
            basicAddressService.add(bap3);
            BasicAddressParam bap4 = new BasicAddressParam();
            bap4.setPutgoodsId(Long.parseLong(bputr2.getId().toString()));
            bap4.setAddress(ExcelItem.getShouhuokehu());
            bar2 = basicAddressService.findBySpec(bap4);
            oodp.setGetLocation(bar2.getAddress());//卸货地址
            oodp.setGetLocationId(Long.parseLong(bar2.getId().toString()));//卸货地址id
            oodp.setGetPeople(bar2.getContacts());//联系人
            oodp.setGetTel(bar2.getTel());//联系电话
        } else if (bar2 == null && ToolUtil.isNotEmpty(ExcelItem.getShouhuokehudizhi())) {//如果没有地址  Excel中有收货客户地址  新增基础数据 地址
            bap3.setAddress(ExcelItem.getShouhuokehudizhi());//地点 (Excel中收货客户地址)
            bap3.setPutgoodsName(bputr2.getPutgoodsName());//单位名称
            bap3.setTel(ExcelItem.getShouhuolianxidianhua());//联系电话 (Excel中的 收货客户电话)
            bap3.setContacts(ExcelItem.getShouhuolianxiren());
            bap3.setLongitude("0");
            bap3.setLatitude("0");
            bap3.setSwitchWl("1");
            bap3.setSwitchBj("1500");//提货围栏半径 默认100米
            bap3.setSwitchBj2("2000");//收货围栏半径 默认100米
            basicAddressService.add(bap3);
            BasicAddressParam bap4 = new BasicAddressParam();
            bap4.setPutgoodsId(Long.parseLong(bputr2.getId().toString()));
            bap4.setAddress(ExcelItem.getShouhuokehudizhi());
            bar2 = basicAddressService.findBySpec(bap4);
            oodp.setGetLocation(bar2.getAddress());//卸货地址
            oodp.setGetLocationId(Long.parseLong(bar2.getId().toString()));//卸货地址id
            oodp.setGetPeople(bar2.getContacts());//联系人
            oodp.setGetTel(bar2.getTel());//联系电话
        }
    }

    //处理单位地址
    private void toDealWith(OrderTransportParam oodp, BasicCustomer basicCustomer, OrderTransportExcelItem ExcelItem, DealWithParam dealWithParam) {
        User user = userService.getcurrentUser();
        //查询装货单位 是否存在
        BasicPutgoodsParam bpgp = new BasicPutgoodsParam();
        if (oodp.getSetUnitId() != null) {
            bpgp.setId(Integer.parseInt(oodp.getSetUnitId().toString()));
        }
        bpgp.setPutgoodsCustomerId(basicCustomer.getId());//客户id
        bpgp.setPutgoodsName(ExcelItem.getZhuanghuodanwei());//单位名称
        BasicPutgoodsResult bputr = basicPutgoodsService.findBySpec(bpgp, null);
        if (bputr == null) {
            bpgp.setPutgoodsOperateName(basicCustomer.getCustomerName());//客户名称
            bpgp.setDeliverId(user.getDeliverId());
            bpgp.setDeptId(user.getDeptId());
            basicPutgoodsService.add(bpgp);
            dealWithParam.setNewCustomersflag(true);
            dealWithParam.setNewCustomers(dealWithParam.getNewCustomers() + "New Consignee Unit：" + ExcelItem.getZhuanghuodanwei() + "，Please promptly maintain the route and correct the address for the new unit to avoid affecting vehicle dispatching and driver delivery.");
            BasicPutgoodsParam bpgp2 = new BasicPutgoodsParam();
            bpgp2.setPutgoodsCustomerId(basicCustomer.getId());//客户id
            bpgp2.setPutgoodsName(ExcelItem.getZhuanghuodanwei());//单位名称
            bputr = basicPutgoodsService.findBySpec(bpgp2, null);
        }
        oodp.setSetUnit(bputr.getPutgoodsName());//装货单位
        oodp.setSetUnitId(Long.parseLong(bputr.getId().toString()));//装货单位id
        //查询装货地点 是否存在
        BasicAddressParam bap = new BasicAddressParam();
        bap.setPutgoodsId(Long.parseLong(bputr.getId().toString()));//单位id
        BasicAddressResult bar = basicAddressService.findBySpec(bap);//通过单位id 地址 查询
        if (bar != null) {
            oodp.setSetLocation(bar.getAddress());//装货地址
            oodp.setSetLocationId(Long.parseLong(bar.getId().toString()));//装货地址id
            oodp.setSetPeople(bar.getContacts());//联系人
            oodp.setSetTel(bar.getTel());//联系电话
        } else if (bar == null && ToolUtil.isEmpty(ExcelItem.getZhuanghuodizhi())) {//如果没有地址 并且Excel中库存地点名称 为空，  装货地址为 单位名称
            BasicWarehouseParam basicWarehouseParam = new BasicWarehouseParam();
            basicWarehouseParam.setWarehouseName(ExcelItem.getZhuanghuodanwei());
            BasicWarehouseResult basicWarehouseResult = basicWarehouseService.findBySpec(basicWarehouseParam, user.getDeptId(), user.getOperateId());
            if (basicWarehouseResult != null) {
                bap.setAddress(basicWarehouseResult.getWarehouseAddress());
                bap.setTel(basicWarehouseResult.getTel());
                bap.setContacts(basicWarehouseResult.getWarehouseContacts());
            } else {
                bap.setAddress(bputr.getPutgoodsName());//地点 为单位名称
                bap.setTel(bputr.getPutgoodsTel());//联系电话 (单位 的联系电话)
                bap.setContacts(bputr.getPutgoodsContacts());
            }
            bap.setPutgoodsName(bputr.getPutgoodsName());//单位名称
            bap.setSwitchBj("1500");//提货围栏半径 默认100米
            bap.setSwitchBj2("2000");//收货围栏半径 默认100米
            basicAddressService.add(bap);
            BasicAddressParam bap2 = new BasicAddressParam();
            bap2.setPutgoodsId(Long.parseLong(bputr.getId().toString()));
            bar = basicAddressService.findBySpec(bap2);
            oodp.setSetLocation(bar.getAddress());//装货地址
            oodp.setSetLocationId(Long.parseLong(bar.getId().toString()));//装货地址id
            oodp.setSetPeople(bar.getContacts());//联系人
            oodp.setSetTel(bar.getTel());//联系电话
        } else if (bar == null && ToolUtil.isNotEmpty(ExcelItem.getZhuanghuodizhi())) {//如果没有地址  Excel中有库存地点名称  新增基础数据 地址
            bap.setAddress(ExcelItem.getZhuanghuodizhi());//地点 (Excel中库存地点名称)
            bap.setPutgoodsName(bputr.getPutgoodsName());//单位名称
            bap.setTel(ExcelItem.getZhuanghuolianxidianhua());//联系电话 (Excel中的 收货客户电话)
            bap.setContacts(ExcelItem.getZhuanghuolianxiren());
            bap.setSwitchBj("1500");//提货围栏半径 默认100米
            bap.setSwitchBj2("2000");//收货围栏半径 默认100米
            basicAddressService.add(bap);
            BasicAddressParam bap2 = new BasicAddressParam();
            bap2.setPutgoodsId(Long.parseLong(bputr.getId().toString()));
            bap2.setAddress(ExcelItem.getZhuanghuodizhi());
            bar = basicAddressService.findBySpec(bap2);
            oodp.setSetLocation(bar.getAddress());//装货地址
            oodp.setSetLocationId(Long.parseLong(bar.getId().toString()));//装货地址id
            oodp.setSetPeople(bar.getContacts());//联系人
            oodp.setSetTel(bar.getTel());//联系电话
        }

        //查询卸货单位 是否存在
        BasicPutgoodsParam bpgp3 = new BasicPutgoodsParam();
        bpgp3.setPutgoodsCustomerId(basicCustomer.getId());//客户id
        bpgp3.setPutgoodsName(ExcelItem.getShouhuokehu());//单位名称  (Excel导入数据中 的收货客户)
        if (ToolUtil.isNotEmpty(ExcelItem.getShouhuokehudizhi())) {
            bpgp3.setLocationAddress(ExcelItem.getShouhuokehudizhi());
        }
        BasicPutgoodsResult bputr2 = basicPutgoodsService.findBySpec(bpgp3, null);
        if (bputr2 == null) {
            bpgp3.setPutgoodsOperateName(basicCustomer.getCustomerName());//客户名称
            bpgp3.setDeliverId(user.getDeliverId());
            bpgp3.setDeptId(user.getDeptId());
            basicPutgoodsService.add(bpgp3);
            dealWithParam.setNewCustomersflag(true);
            dealWithParam.setNewCustomers(dealWithParam.getNewCustomers() + "New Consignee Unit：" + ExcelItem.getShouhuokehu() + "，Please promptly maintain the route and correct the address for the new unit to avoid affecting vehicle dispatching and driver delivery.");
            BasicPutgoodsParam bpgp4 = new BasicPutgoodsParam();
            bpgp4.setPutgoodsCustomerId(basicCustomer.getId());//客户id
            bpgp4.setPutgoodsName(ExcelItem.getShouhuokehu());//单位名称
            bputr2 = basicPutgoodsService.findBySpec(bpgp4, null);
        }
        oodp.setGetUnit(bputr2.getPutgoodsName());//卸货单位
        oodp.setGetUnitId(Long.parseLong(bputr2.getId().toString()));//卸货单位id
        //查询卸货地点 是否存在
        BasicAddressParam bap3 = new BasicAddressParam();
        bap3.setPutgoodsId(Long.parseLong(bputr2.getId().toString()));//单位id
        if (ToolUtil.isNotEmpty(ExcelItem.getShouhuokehudizhi())) {
            bap3.setAddress(ExcelItem.getShouhuokehudizhi());
        }
        BasicAddressResult bar2 = basicAddressService.findBySpec(bap3);//通过单位id 地址 查询
        if (bar2 != null) {
            oodp.setGetLocationId(Long.parseLong(bar2.getId().toString()));//卸货地址id
            if (ToolUtil.isNotEmpty(ExcelItem.getShouhuokehudizhi())) {
                bap3.setAddress(ExcelItem.getShouhuokehudizhi());
                oodp.setGetLocation(ExcelItem.getShouhuokehudizhi());//卸货地址
            } else {
                oodp.setGetLocation(bar2.getAddress());//卸货地址
            }
            if (ToolUtil.isNotEmpty(ExcelItem.getShouhuolianxiren())) {
                bap3.setContacts(ExcelItem.getShouhuolianxiren());
                oodp.setGetPeople(ExcelItem.getShouhuolianxiren());//联系人
            } else {
                oodp.setGetPeople(bar2.getContacts());//联系人
            }
            if (ToolUtil.isNotEmpty(ExcelItem.getShouhuolianxidianhua())) {
                bap3.setTel(ExcelItem.getShouhuolianxidianhua());
                oodp.setGetTel(ExcelItem.getShouhuolianxidianhua());//联系电话
            } else {
                oodp.setGetTel(bar2.getTel());//联系电话
            }
            bap3.setId(bar2.getId());
            basicAddressService.update(bap3);
            oodp.setKilometer(bar2.getKilometer());
            oodp.setLineId(bar2.getLineId());
            oodp.setLineName(bar2.getLineName());
        } else if (bar2 == null && ToolUtil.isEmpty(ExcelItem.getShouhuokehudizhi())) {//如果没有地址 并且Excel中收货客户地址 为空，  卸货地址为 单位名称
            bap3.setAddress(bputr2.getPutgoodsName());//地点 为单位名称
            bap3.setPutgoodsName(bputr2.getPutgoodsName());//单位名称
            bap3.setTel(bputr2.getPutgoodsTel());//联系电话 (单位 的联系电话)
            bap3.setContacts(bputr2.getPutgoodsContacts());
            bap3.setLongitude("0");
            bap3.setLatitude("0");
            bap3.setSwitchWl("1");
            bap3.setSwitchBj("1500");//提货围栏半径 默认100米
            bap3.setSwitchBj2("2000");//收货围栏半径 默认100米
            basicAddressService.add(bap3);
            BasicAddressParam bap4 = new BasicAddressParam();
            bap4.setPutgoodsId(Long.parseLong(bputr2.getId().toString()));
            bap4.setAddress(ExcelItem.getShouhuokehu());
            bar2 = basicAddressService.findBySpec(bap4);
            oodp.setGetLocation(bar2.getAddress());//卸货地址
            oodp.setGetLocationId(Long.parseLong(bar2.getId().toString()));//卸货地址id
            oodp.setGetPeople(bar2.getContacts());//联系人
            oodp.setGetTel(bar2.getTel());//联系电话
        } else if (bar2 == null && ToolUtil.isNotEmpty(ExcelItem.getShouhuokehudizhi())) {//如果没有地址  Excel中有收货客户地址  新增基础数据 地址
            bap3.setAddress(ExcelItem.getShouhuokehudizhi());//地点 (Excel中收货客户地址)
            bap3.setPutgoodsName(bputr2.getPutgoodsName());//单位名称
            bap3.setTel(ExcelItem.getShouhuolianxidianhua());//联系电话 (Excel中的 收货客户电话)
            bap3.setContacts(ExcelItem.getShouhuolianxiren());
            bap3.setLongitude("0");
            bap3.setLatitude("0");
            bap3.setSwitchWl("1");
            bap3.setSwitchBj("1500");//提货围栏半径 默认100米
            bap3.setSwitchBj2("2000");//收货围栏半径 默认100米
            basicAddressService.add(bap3);
            BasicAddressParam bap4 = new BasicAddressParam();
            bap4.setPutgoodsId(Long.parseLong(bputr2.getId().toString()));
            bap4.setAddress(ExcelItem.getShouhuokehudizhi());
            bar2 = basicAddressService.findBySpec(bap4);
            oodp.setGetLocation(bar2.getAddress());//卸货地址
            oodp.setGetLocationId(Long.parseLong(bar2.getId().toString()));//卸货地址id
            oodp.setGetPeople(bar2.getContacts());//联系人
            oodp.setGetTel(bar2.getTel());//联系电话
        }
    }

    public static void main(String[] args) {
        String a = "由出库申请单CK666664990033575,CK666664990033463合并生成";
        //System.out.println(a.indexOf("合并生成"));
    }

    @Resource
    private OrderOutcountXlbService orderOutcountXlbService;

    @Resource
    private BasicXlbOauth2tokenService basicXlbOauth2tokenService;

    @Override
    public OrderTransportResult checkyouwu(OrderTransportParam ch) {
        return this.baseMapper.checkyouwu(ch);
    }

    @Override
    public void updateOauth2TokenXlb() {
        BasicXlbOauth2tokenParam oauth2tokenParam = new BasicXlbOauth2tokenParam();
        List<BasicXlbOauth2tokenResult> list = basicXlbOauth2tokenService.findListBySpec(oauth2tokenParam);
        for (BasicXlbOauth2tokenResult c : list) {
            String url = "";
            String Authorization = "";
            if (c.getGsnumber().equals("1000")) {
                url = "https://test-api.xlbsoft.com/auth/oauth/token?refresh_token=" + c.getOauth2RefreshTokenXlb() + "&grant_type=refresh_token";
                Authorization = "Basic N2MzYWY3NzZhYTQ3NGJjYjkwYzY0NjBjNDg0ZDEzYjk6ZDVlMWNlMmViOTVmNGQ2Zjg0MjIwODg4NDRiNTg4NDc=";
            } else {
                url = "https://hxl-api.xlbsoft.com/auth/oauth/token?refresh_token=" + c.getOauth2RefreshTokenXlb() + "&grant_type=refresh_token";
                Authorization = "Basic N2ZhMTEwMWU1OTU5NDE4OTkxN2VjNzBlMzY3ZGI5ODQ6NjA1ODM2N2YwNjAyNDhmNTlkY2E3MTNjZDg2YjU3MTQ=";
            }
            String post = HttpRequest.post(url)
                    .header("Content-Type", "application/x-www-form-urlencoded").header("Authorization", Authorization).execute().body();
            JSONObject jsonObject = new JSONObject(post);
//			System.out.println("================post："+post+"========================");
            String access_token = jsonObject.get("access_token").toString();
            if (ToolUtil.isNotEmpty(access_token) && !access_token.equals("null")) {
                BasicXlbOauth2tokenParam update = new BasicXlbOauth2tokenParam();
                update.setId(c.getId());
                update.setOauth2TokenXlb(access_token);
                String refresh_token = jsonObject.get("refresh_token").toString();
                update.setOauth2RefreshTokenXlb(refresh_token);
                basicXlbOauth2tokenService.update(update);
            }
        }


    }

    @Override
    public OrderTransportResult carDetailsSingleToo1(OrderTransportParam oParam, Long carId, Long operateId) {
        return this.baseMapper.carDetailsSingleToo1(oParam, carId, operateId);
    }

    @Override
    public List<OrderTransportResult> carDetailsSingleToo3(OrderTransportParam orderTransportParam) {
        return this.baseMapper.carDetailsSingleToo3(orderTransportParam);
    }

    @Override
    public List<OrderTransportResult> findOrderTransportCountDataBySpec(OrderTransportParam orderTransportParam,
                                                                        String month) {
        return this.baseMapper.findOrderTransportCountDataBySpec(orderTransportParam, month);
    }

    @Override
    public LayuiPageInfo findAllOrder() {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findAllOrder(pageContext);
        return LayuiPageFactory.createPageInfo(page);

    }

    @Override
    public List<OrderTransportResult> findStockPort(OrderTransportParam orderTransportParam2) {
        return this.baseMapper.findStockPort(orderTransportParam2);
    }

	@Override
	public OrderTransportResult findByTransportNumberOrOrderNumber(OrderTransportParam otp) {
		return this.baseMapper.findByTransportNumberOrOrderNumber(otp);
	}

	@Override
	public List<OrderTransportResult> findPieceNumberNumBySpec(String dispatchNumber) {
		return this.baseMapper.findPieceNumberNumBySpec(dispatchNumber);
	}

    @Override
    public List<OrderTransportResult> getUnitList(String dispatchNumber) {
        return this.baseMapper.getUnitList(dispatchNumber);
    }

}
